package com.chicken.henhouse.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;






import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chicken.henhouse.pojo.Ch_Hencoop_Control_Task;
import com.chicken.henhouse.pojo.Ch_Hencoop_Task;
import com.chicken.henhouse.pojo.Ch_Hencoop_Control;
import com.chicken.henhouse.pojo.Ch_Hencoop_Control_Item;
import com.chicken.henhouse.service.ControlService;
import com.chicken.henhouse.service.ControlTaskService;
import com.chicken.henhouse.service.HencoopTaskService;
import com.chicken.henhouse.service.ItemService;
import com.google.gson.Gson;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

import freemarker.core.ParseException;

@Controller
@Api(value = "/")
public class ChickenController {
	
	@Resource
	public ControlService service1;
	//@RequestMapping(value = "/add", method = RequestMethod.GET)
	@RequestMapping("/addBrithMonth")
	@ResponseBody
	@ApiOperation(value="测试1")
    public String AddChicken(@ApiParam(required=true,value="出生月份",name="brith_month")@RequestParam(value="brith_month") String brith_month,HttpServletRequest req) throws java.text.ParseException, UnsupportedEncodingException {
        req.setCharacterEncoding("utf-8");
		//resp.setContentType("text/html;charset=utf-8");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date create_date=sdf.parse("2012-1-3");
		Date modify_date=sdf.parse("2012-1-2");
		int sn=1;
		
		String brith_month1=req.getParameter("brith_month");
		
		
		int ch_chicken_varieties_id=7;
		int farmer_id=1;
		Ch_Hencoop_Control brithMonth=new Ch_Hencoop_Control(create_date,modify_date,sn,brith_month1,ch_chicken_varieties_id,farmer_id);
		int add =service1.addBrithMonth(brithMonth);
		
		Gson g=new Gson();
		
		String j=g.toJson(add);
		return j;
		
	}
	
	@Resource
	public ItemService service2;
	@RequestMapping("/addControl")
	@ResponseBody
	@ApiOperation(value="测试2")

    public String AddChicken1(@ApiParam(required=true,value="开始日龄",name="age_range_begin")@RequestParam(value="age_range_begin") int age_range_begin,@ApiParam(required=true,value="结束日龄",name="age_range_end")@RequestParam(value="age_range_end") int age_range_end,HttpServletRequest req) throws ParseException, IOException, java.text.ParseException{
		req.setCharacterEncoding("utf-8");
		//resp.setContentType("text/html;charset=utf-8");
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date create_date=sdf.parse("2013-2-4");
		Date modify_date=sdf.parse("2013-2-4");
		String open_door_date="04:33";
		String shut_door_date="04:33";
		String morning_open_trough_date="04:33";
		String in_open_trough_date="04:33";
		String night_open_trough_date="04:33";
		String open_lamp_date="04:33";
		String shut_lamp_date="04:33";
		int heat_low_temperature=1;
		int heat_high_temperature=1;
		int fan_low_temperature=1;
		int fan_high_temperature=1;
		int  age_range_begin1=Integer.parseInt(req.getParameter("age_range_begin"));
		int  age_range_end1=Integer.parseInt(req.getParameter("age_range_end"));
		int ch_hencoop_control_id=1;
		Ch_Hencoop_Control_Item item=new Ch_Hencoop_Control_Item(create_date,modify_date,open_door_date,shut_door_date,morning_open_trough_date,in_open_trough_date,night_open_trough_date,open_lamp_date,shut_lamp_date,heat_low_temperature,heat_high_temperature,fan_low_temperature,fan_high_temperature,age_range_begin1,age_range_end1,ch_hencoop_control_id);
		int add =service2.addItem(item);
       
        Gson g=new Gson();
		
		String b=g.toJson(add);
		return b;
	}
	
	
    @Resource
	public HencoopTaskService service3;
    @RequestMapping("/addOrder")
	@ResponseBody
	@ApiOperation(value="测试3")
	public String InsertChicken(@ApiParam(required=true,value="排序",name="order")@RequestParam(value="order") int order,HttpServletRequest req) throws UnsupportedEncodingException, java.text.ParseException{
		req.setCharacterEncoding("utf-8");
		//resp.setContentType("text/html;charset=utf-8");
		
		int id=28;
		SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
		Date create_date=sdf.parse("2011-1-2");
		Date modify_date=sdf.parse("2013-2-3");
		String task_name="打开食槽";
		int order1=Integer.parseInt(req.getParameter("order"));
		Ch_Hencoop_Task task=new Ch_Hencoop_Task(id,create_date,modify_date,task_name,order1);
		int insert=service3.addHencoopTask(task);
		Gson g=new Gson();
		String c=g.toJson(insert);
		return c;
	}
	
	@Resource
	public ControlTaskService service4;
	@RequestMapping("/addType")
	@ResponseBody
	@ApiOperation(value="测试4")
    public String AddChicken3(@ApiParam(required=true,value="开始时间",name="create_date")@RequestParam(value="create_date") String create_date,@ApiParam(required=true,value="任务名称",name="task_name")@RequestParam(value="task_name") String task_name,@ApiParam(required=true,value="类型",name="name_type")@RequestParam(value="name_type") int name_type,HttpServletRequest req) throws ParseException, IOException, java.text.ParseException{
		req.setCharacterEncoding("utf-8");
		//resp.setContentType("text/html;charset=utf-8");
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		//需转换成time类型
		
		//Date create_date = sdf.parse("2014-2-1");
		String create_date1=req.getParameter("create_date");
		
		Date modify_date = sdf.parse("2014-2-3");
		String task_name1=req.getParameter("task_name");
		//十进制
		int name_type1=(Integer.parseInt(req.getParameter("name_type")));
		Ch_Hencoop_Control_Task task=new Ch_Hencoop_Control_Task(create_date1,modify_date,task_name1,name_type1);
		int add=service4.addControlTask(task);
	    Gson g=new Gson();
		
	    String d=g.toJson(add);
	    return d;
	}

	}
	

